<div class="container">
    <h1 id="pkg-overview">package big</h1>
    <p><code>import "math/big"</code>
    </p><p>big包实现了大数字的多精度计算。 支持如下数字类型：</p>
    <pre>- Int	有符号整数
- Rat	有理数</pre>
    <p>方法一般为如下格式：</p>
    <pre>func (z *Int) Op(x, y *Int) *Int	(similar for *Rat)
</pre>
    <p>该方法实现了操作z = x Op y：计算并将结果写入z。如果结果是操作数之一，可能会重写该参数（重用其内存）；为了实现链式的计算，计算结果同时会作为返回值。方法返回一个结果而不是让*Int/*Rat调用方法获取另一个操作数。</p>
    
    
		
        
        
        
        
        
        
    
    
    
		
        
        
        
        
    
    <h2 id="pkg-constants">Constants </h2>
    <pre>const <span id="MaxBase">MaxBase</span> = 'z' - 'a' + 10 + 1 <span class="com">// = hexValue('z') + 1</span>
</pre>
    <p>MaxBase是字符串转换函数接受的最大进制。</p>
    <h2 id="Word">type <a href="https://github.com/golang/go/blob/master/src/math/big/arith.go?name=release#12" title="View Source">Word</a> </h2>
    <pre>type Word <a href="builtin.htm#uintptr">uintptr</a></pre>
    <p>Word代表一个多精度无符号整数的单个数字。</p>
    <h2 id="Int">type <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#19" title="View Source">Int</a> </h2>
    <pre>type Int struct {
    <span class="com">// 内含隐藏或非导出字段</span>
}</pre>
    <p>Int类型代表多精度的整数，零值代表数字0。</p>
    <h3 id="NewInt">func <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#62" title="View Source">NewInt</a> </h3>
    <pre class="funcdecl">func NewInt(x <a href="builtin.htm#int64">int64</a>) *<a href="#Int">Int</a></pre>
    <p>创建一个值为x的*Int。</p>
    <h3 id="Int.Int64">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#515" title="View Source">Int64</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Int">Int</a>) Int64() <a href="builtin.htm#int64">int64</a></pre>
    <p>返回x的int64表示，如果不能用int64表示，结果是未定义的。</p>
    <h3 id="Int.Uint64">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#525" title="View Source">Uint64</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Int">Int</a>) Uint64() <a href="builtin.htm#uint64">uint64</a></pre>
    <p>返回x的uint64表示，如果不能用uint64表示，结果是未定义的。</p>
    <h3 id="Int.Bytes">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#567" title="View Source">Bytes</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Int">Int</a>) Bytes() []<a href="builtin.htm#byte">byte</a></pre>
    <p>返回x的绝对值的大端在前的字节切片表示。</p>
    <h3 id="Int.String">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#324" title="View Source">String</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Int">Int</a>) String() <a href="builtin.htm#string">string</a></pre>
    <h3 id="Int.BitLen">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#574" title="View Source">BitLen</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Int">Int</a>) BitLen() <a href="builtin.htm#int">int</a></pre>
    <p>返回x的绝对值的字位数，0的字位数为0。</p>
    <h3 id="Int.Bits">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#80" title="View Source">Bits</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Int">Int</a>) Bits() []<a href="#Word">Word</a></pre>
    <p>提供了对x的数据不检查而快速的访问，返回构成x的绝对值的小端在前的word切片。该切片与x的底层是同一个数组，本函数用于支持在包外实现缺少的低水平功能，否则不应被使用。</p>
    <h3 id="Int.Bit">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#774" title="View Source">Bit</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Int">Int</a>) Bit(i <a href="builtin.htm#int">int</a>) <a href="builtin.htm#uint">uint</a></pre>
    <p>返回第i个字位的值，即返回(x&gt;&gt;i)&amp;1。i必须不小于0。</p>
    <h3 id="Int.SetInt64">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#43" title="View Source">SetInt64</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) SetInt64(x <a href="builtin.htm#int64">int64</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为x并返回z。</p>
    <h3 id="Int.SetUint64">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#55" title="View Source">SetUint64</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) SetUint64(x <a href="builtin.htm#uint64">uint64</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为x并返回z。</p>
    <h3 id="Int.SetBytes">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#560" title="View Source">SetBytes</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) SetBytes(buf []<a href="builtin.htm#byte">byte</a>) *<a href="#Int">Int</a></pre>
    <p>将buf视为一个大端在前的无符号整数，将z设为该值，并返回z。</p>
    <h3 id="Int.SetString">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#545" title="View Source">SetString</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) SetString(s <a href="builtin.htm#string">string</a>, base <a href="builtin.htm#int">int</a>) (*<a href="#Int">Int</a>, <a href="builtin.htm#bool">bool</a>)</pre>
    <p>将z设为s代表的值（base为基数）。返回z并用一个bool来表明成功与否。如果失败，z的值是不确定的，但返回值为nil。基数必须是0或者2到MaxBase之间的整数。如果基数为0，字符串的前缀决定实际的转换基数："0x"、"0X"表示十六进制；"0b"、"0B"表示二进制；"0"表示八进制；否则为十进制。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-Int-SetString">
            <div class="panel-heading" onclick="document.getElementById('ex-Int-SetString').style.display = document.getElementById('ex-Int-SetString').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-Int-SetString">
                <div class="panel-body">
                    <pre>i := new(big.Int)
i.SetString("644", 8) <span class="com">// octal</span>
fmt.Println(i)</pre>
                    <p>Output:
                    </p><pre>420
</pre>
                </div>
            </div>
        </div>
    </div>
    <h3 id="Int.SetBits">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#89" title="View Source">SetBits</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) SetBits(abs []<a href="#Word">Word</a>) *<a href="#Int">Int</a></pre>
    <p>提供了对z的数据不检查而快速的操作，将abs视为小端在前的word切片并直接赋给z，返回z。会将z的底层设置为abs的同一底层数组，本函数用于支持在包外实现缺少的低水平功能，否则不应被使用。</p>
    <h3 id="Int.SetBit">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#797" title="View Source">SetBit</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) SetBit(x *<a href="#Int">Int</a>, i <a href="builtin.htm#int">int</a>, b <a href="builtin.htm#uint">uint</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为x并设置z的第i位为b，返回z。如b为1，z = x | (1 &lt;&lt; i)；如b为0，z = x &amp; ^(1 &lt;&lt; i)；否则会panic。</p>
    <h3 id="Int.MulRange">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#165" title="View Source">MulRange</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) MulRange(a, b <a href="builtin.htm#int64">int64</a>) *<a href="#Int">Int</a></pre>
    <p>将z设置为区间[a, b]内所有整数的乘积A(a, b)，并返回z。如果a&gt;b会将z设为1并返回。</p>
    <h3 id="Int.Binomial">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#186" title="View Source">Binomial</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Binomial(n, k <a href="builtin.htm#int64">int64</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为k次二项式展开第n项的系数C(n, k)，并返回z。</p>
    <h3 id="Int.Rand">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#726" title="View Source">Rand</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Rand(rnd *<a href="math/rand.htm">rand</a>.<a href="math/rand.htm#Rand">Rand</a>, n *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为一个范围在[0, n)的伪随机值，并返回z。</p>
    <h3 id="Int.ProbablyPrime">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#721" title="View Source">ProbablyPrime</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Int">Int</a>) ProbablyPrime(n <a href="builtin.htm#int">int</a>) <a href="builtin.htm#bool">bool</a></pre>
    <p>对x进行n次Miller-Rabin质数检测。如果方法返回真则x是质数的几率为1-(1/4)**n；否则x不是质数。</p>
    <h3 id="Int.Sign">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#32" title="View Source">Sign</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Int">Int</a>) Sign() <a href="builtin.htm#int">int</a></pre>
    <p>返回x的正负号。x&lt;0时返回-1；x&gt;0时返回+1；否则返回0。</p>
    <h3 id="Int.Cmp">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#305" title="View Source">Cmp</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Int">Int</a>) Cmp(y *<a href="#Int">Int</a>) (r <a href="builtin.htm#int">int</a>)</pre>
    <p>比较x和y的大小。x&lt;y时返回-1；x&gt;y时返回+1；否则返回0。</p>
    <h3 id="Int.Not">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#937" title="View Source">Not</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Not(x *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为^x并返回z（按位取反）。</p>
    <h3 id="Int.And">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#814" title="View Source">And</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) And(x, y *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为x &amp; y并返回z（按位且）。</p>
    <h3 id="Int.Or">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#877" title="View Source">Or</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Or(x, y *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为x | y并返回z（按位或）。</p>
    <h3 id="Int.Xor">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#907" title="View Source">Xor</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Xor(x, y *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为x ^ y并返回z（按位异或）。</p>
    <h3 id="Int.AndNot">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#844" title="View Source">AndNot</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) AndNot(x, y *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为x &amp; (^y)并返回z（按位减）。</p>
    <h3 id="Int.Lsh">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#750" title="View Source">Lsh</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Lsh(x *<a href="#Int">Int</a>, n <a href="builtin.htm#uint">uint</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为x &lt;&lt; n并返回z（左位移运算）。</p>
    <h3 id="Int.Rsh">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#757" title="View Source">Rsh</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Rsh(x *<a href="#Int">Int</a>, n <a href="builtin.htm#uint">uint</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为x &gt;&gt; n并返回z（右位移运算）。</p>
    <h3 id="Int.Abs">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#96" title="View Source">Abs</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Abs(x *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为|x|并返回z。</p>
    <h3 id="Int.Neg">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#103" title="View Source">Neg</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Neg(x *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为-x并返回z。</p>
    <h3 id="Int.Set">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#67" title="View Source">Set</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Set(x *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为x（生成一个拷贝）并返回z</p>
    <h3 id="Int.Add">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#110" title="View Source">Add</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Add(x, y *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为x + y并返回z。</p>
    <h3 id="Int.Sub">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#131" title="View Source">Sub</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Sub(x, y *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为x - y并返回z。</p>
    <h3 id="Int.Mul">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#152" title="View Source">Mul</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Mul(x, y *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为x * y并返回z。</p>
    <h3 id="Int.Div">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#232" title="View Source">Div</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Div(x, y *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>如果y != 0会将z设为x/y并返回z；如果y==0会panic。函数采用欧几里德除法（和Go不同），参见DivMod。</p>
    <h3 id="Int.Mod">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#249" title="View Source">Mod</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Mod(x, y *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>如果y != 0会将z设为x%y并返回z；如果y==0会panic。函数采用欧几里德除法（和Go不同），参见DivMod。</p>
    <h3 id="Int.DivMod">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#281" title="View Source">DivMod</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) DivMod(x, y, m *<a href="#Int">Int</a>) (*<a href="#Int">Int</a>, *<a href="#Int">Int</a>)</pre>
    <p align="left">如果y != 0将z设为x/y，将m设为x%y并返回(z, m)；如果y == 0会panic。采用欧几里德除法（和Go不同）</p>
    <p align="left">DivMod方法实现了欧几里德带余除法：</p>
    <pre>q = x div y  满足
m = x - y*q  且 0 &lt;= m &lt; |q|
</pre>
    <h3 id="Int.Quo">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#196" title="View Source">Quo</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Quo(x, y *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>如果y != 0会将z设为x/y并返回z；如果y==0会panic。函数采用截断除法（和Go相同），参见QuoRem。</p>
    <h3 id="Int.Rem">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#205" title="View Source">Rem</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Rem(x, y *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>如果y != 0会将z设为x%y并返回z；如果y==0会panic。函数采用截断除法（和Go相同），参见QuoRem。</p>
    <h3 id="Int.QuoRem">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#223" title="View Source">QuoRem</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) QuoRem(x, y, r *<a href="#Int">Int</a>) (*<a href="#Int">Int</a>, *<a href="#Int">Int</a>)</pre>
    <p align="left">如果y != 0将z设为x/y，将r设为x%y并返回(z, r)；如果y == 0会panic。函数采用截断除法（和Go相同）</p>
    <p align="left">QuoRem方法实现了截断带余除法：</p>
    <pre>q = x/y      返回值向零的方向截断
r = x - y*q</pre>
    <h3 id="Int.ModInverse">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#738" title="View Source">ModInverse</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) ModInverse(g, p *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为g相对p的模逆（即z、g满足(z * g) % p == 1）。返回值z大于0小于p。</p>
    <h3 id="Int.Exp">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#581" title="View Source">Exp</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Exp(x, y, m *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为x**y mod |m|并返回z；如果y &lt;= 0，返回1；如果m == nil 或 m == 0，z设为x**y。</p>
    <h3 id="Int.GCD">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#602" title="View Source">GCD</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) GCD(x, y, a, b *<a href="#Int">Int</a>) *<a href="#Int">Int</a></pre>
    <p>将z设为a和b的最大公约数并返回z。a或b为nil时会panic；a和b都&gt;0时设置z为最大公约数；如果任一个&lt;=0方法就会设置z = x = y = 0。如果x和y都不是nil，会将x和y设置为满足a*x + b*y==z。</p>
    <h3 id="Int.Format">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#371" title="View Source">Format</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Int">Int</a>) Format(s <a href="fmt.htm">fmt</a>.<a href="fmt.htm#State">State</a>, ch <a href="builtin.htm#rune">rune</a>)</pre>
    <p align="left">Format方法实现了fmt.Formatter接口。本方法接受格式'b'（二进制）、'o'（八进制）、'd'（十进制）、'x'（小写十六进制）、'X'（大写十六进制）。</p>
    <p align="left">方法支持全套fmt包对整数类型的动作：包括用于符号控制的'+'、'-'、' '；用于十六进制和八进制前导0的'#'；"%#x"和"%#X"会设置前导的"0x"或"0X"；指定最小数字精度；输出字段宽度；空格或'0'的补位；左右对齐。</p>
    <h3 id="Int.Scan">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#492" title="View Source">Scan</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) Scan(s <a href="fmt.htm">fmt</a>.<a href="fmt.htm#ScanState">ScanState</a>, ch <a href="builtin.htm#rune">rune</a>) <a href="builtin.htm#error">error</a></pre>
    <p>Scan实现了fmt.Scanner接口，将z设为读取的数字。方法可以接受接受格式'b'（二进制）、'o'（八进制）、'd'（十进制）、'x'（小写十六进制）、'X'（大写十六进制）。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-Int-Scan">
            <div class="panel-heading" onclick="document.getElementById('ex-Int-Scan').style.display = document.getElementById('ex-Int-Scan').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-Int-Scan">
                <div class="panel-body">
                    <pre><span class="com">// The Scan function is rarely used directly;</span>
<span class="com">// the fmt package recognizes it as an implementation of fmt.Scanner.</span>
i := new(big.Int)
_, err := fmt.Sscan("18446744073709551617", i)
if err != nil {
    log.Println("error scanning value:", err)
} else {
    fmt.Println(i)
}</pre>
                    <p>Output:
                    </p><pre>18446744073709551617
</pre>
                </div>
            </div>
        </div>
    </div>
    <h3 id="Int.GobEncode">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#955" title="View Source">GobEncode</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Int">Int</a>) GobEncode() ([]<a href="builtin.htm#byte">byte</a>, <a href="builtin.htm#error">error</a>)</pre>
    <p>本方法实现了gob.GobEncoder接口。</p>
    <h3 id="Int.GobDecode">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#970" title="View Source">GobDecode</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) GobDecode(buf []<a href="builtin.htm#byte">byte</a>) <a href="builtin.htm#error">error</a></pre>
    <p>本方法实现了gob.GobDecoder接口。</p>
    <h3 id="Int.MarshalJSON">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#986" title="View Source">MarshalJSON</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) MarshalJSON() ([]<a href="builtin.htm#byte">byte</a>, <a href="builtin.htm#error">error</a>)</pre>
    <p>本方法实现了json.Marshaler接口。</p>
    <h3 id="Int.UnmarshalJSON">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#992" title="View Source">UnmarshalJSON</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) UnmarshalJSON(text []<a href="builtin.htm#byte">byte</a>) <a href="builtin.htm#error">error</a></pre>
    <p>本方法实现了json.Unmarshaler接口。</p>
    <h3 id="Int.MarshalText">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#1001" title="View Source">MarshalText</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) MarshalText() (text []<a href="builtin.htm#byte">byte</a>, err <a href="builtin.htm#error">error</a>)</pre>
    <p>本方法实现了encoding.TextMarshaler接口。</p>
    <h3 id="Int.UnmarshalText">func (*Int) <a href="https://github.com/golang/go/blob/master/src/math/big/int.go?name=release#1006" title="View Source">UnmarshalText</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Int">Int</a>) UnmarshalText(text []<a href="builtin.htm#byte">byte</a>) <a href="builtin.htm#error">error</a></pre>
    <p>本方法实现了encoding.TextUnmarshaler接口。</p>
    <h2 id="Rat">type <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#19" title="View Source">Rat</a> </h2>
    <pre>type Rat struct {
    <span class="com">// 内含隐藏或非导出字段</span>
}</pre>
    <p>Rat类型代表一个任意精度的有理数（底层采用分数表示），Rat的零值代表数字0。</p>
    <h3 id="NewRat">func <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#27" title="View Source">NewRat</a> </h3>
    <pre class="funcdecl">func NewRat(a, b <a href="builtin.htm#int64">int64</a>) *<a href="#Rat">Rat</a></pre>
    <p>NewRat函数使用分子a和分母b创建一个Rat。</p>
    <h3 id="Rat.Num">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#285" title="View Source">Num</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Rat">Rat</a>) Num() *<a href="#Int">Int</a></pre>
    <p>返回x的分子，分子可能&lt;=0。返回的是x分子的指针，因此对返回值的操作可能改变x，反之亦然。x的符号与分子的符号是绑定的。</p>
    <h3 id="Rat.Denom">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#292" title="View Source">Denom</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Rat">Rat</a>) Denom() *<a href="#Int">Int</a></pre>
    <p>返回x的分母，分母总是&gt;0。返回的是x分母的指针，因此对返回值的操作可能改变x，反之亦然。</p>
    <h3 id="Rat.Float64">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#170" title="View Source">Float64</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Rat">Rat</a>) Float64() (f <a href="builtin.htm#float64">float64</a>, exact <a href="builtin.htm#bool">bool</a>)</pre>
    <p>返回最接近x的值的float64值，exact用于说明f是否精确的表示了x。  如果x的量级太大或太小不能被float64类型表示，返回无穷和false；f的符号始终与x的符号一致，即使f==0。</p>
    <h3 id="Rat.RatString">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#491" title="View Source">RatString</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Rat">Rat</a>) RatString() <a href="builtin.htm#string">string</a></pre>
    <p>返回z的字符串表示，如果分母不等于1，格式为"a/b"；否则格式为"a"。</p>
    <h3 id="Rat.FloatString">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#500" title="View Source">FloatString</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Rat">Rat</a>) FloatString(prec <a href="builtin.htm#int">int</a>) <a href="builtin.htm#string">string</a></pre>
    <p>返回z的字符串表示为精度为prec的十进制浮点数，最后一位会进行四舍五入。</p>
    <h3 id="Rat.String">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#481" title="View Source">String</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Rat">Rat</a>) String() <a href="builtin.htm#string">string</a></pre>
    <p>返回z的字符串表示，格式为"a/b"（即使分母等于1）。</p>
    <h3 id="Rat.IsInt">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#277" title="View Source">IsInt</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Rat">Rat</a>) IsInt() <a href="builtin.htm#bool">bool</a></pre>
    <p>返回x的分母是否为1（即x为整数）。</p>
    <h3 id="Rat.SetInt64">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#219" title="View Source">SetInt64</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) SetInt64(x <a href="builtin.htm#int64">int64</a>) *<a href="#Rat">Rat</a></pre>
    <p>将z设为x，并返回z。</p>
    <h3 id="Rat.SetFrac64">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#198" title="View Source">SetFrac64</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) SetFrac64(a, b <a href="builtin.htm#int64">int64</a>) *<a href="#Rat">Rat</a></pre>
    <p>将z设为a/b，并返回z。</p>
    <h3 id="Rat.SetFloat64">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#33" title="View Source">SetFloat64</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) SetFloat64(f <a href="builtin.htm#float64">float64</a>) *<a href="#Rat">Rat</a></pre>
    <p>将z设为f的精确值并返回z。如果f不是有穷数（即f为+Inf、+Inf或NaN）时会返回nil。。</p>
    <h3 id="Rat.SetInt">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#212" title="View Source">SetInt</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) SetInt(x *<a href="#Int">Int</a>) *<a href="#Rat">Rat</a></pre>
    <p>将z设为x（生成一个拷贝）并返回z。</p>
    <h3 id="Rat.SetFrac">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#183" title="View Source">SetFrac</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) SetFrac(a, b *<a href="#Int">Int</a>) *<a href="#Rat">Rat</a></pre>
    <p>将z设为a/b，并返回z。</p>
    <h3 id="Rat.SetString">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#426" title="View Source">SetString</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) SetString(s <a href="builtin.htm#string">string</a>) (*<a href="#Rat">Rat</a>, <a href="builtin.htm#bool">bool</a>)</pre>
    <p>将z设为字符串代表的值，返回z并用一个bool表明是否成功。字符串s的格式可以是形如"a/b"的分数格式，也可以是浮点数后跟可选的指数的科学计数法格式。如果操作失败，z的值是不确定的，但返回值为nil。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-Rat-SetString">
            <div class="panel-heading" onclick="document.getElementById('ex-Rat-SetString').style.display = document.getElementById('ex-Rat-SetString').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-Rat-SetString">
                <div class="panel-body">
                    <pre>r := new(big.Rat)
r.SetString("355/113")
fmt.Println(r.FloatString(3))</pre>
                    <p>Output:
                    </p><pre>3.142
</pre>
                </div>
            </div>
        </div>
    </div>
    <h3 id="Rat.Sign">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#272" title="View Source">Sign</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Rat">Rat</a>) Sign() <a href="builtin.htm#int">int</a></pre>
    <p>返回x的正负号。如x &lt; 0返回-1；如x &gt; 0返回+1；否则返回0。</p>
    <h3 id="Rat.Cmp">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#359" title="View Source">Cmp</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Rat">Rat</a>) Cmp(y *<a href="#Rat">Rat</a>) <a href="builtin.htm#int">int</a></pre>
    <p>比较x和y的大小。如x &lt; y返回-1；如x &gt; y返回+1；否则返回0。</p>
    <h3 id="Rat.Abs">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#235" title="View Source">Abs</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) Abs(x *<a href="#Rat">Rat</a>) *<a href="#Rat">Rat</a></pre>
    <p>将z设为|x|并返回z。</p>
    <h3 id="Rat.Neg">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#242" title="View Source">Neg</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) Neg(x *<a href="#Rat">Rat</a>) *<a href="#Rat">Rat</a></pre>
    <p>将z设为-x并返回z。</p>
    <h3 id="Rat.Inv">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#249" title="View Source">Inv</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) Inv(x *<a href="#Rat">Rat</a>) *<a href="#Rat">Rat</a></pre>
    <p>将z设为1/x并返回z。</p>
    <h3 id="Rat.Set">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#226" title="View Source">Set</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) Set(x *<a href="#Rat">Rat</a>) *<a href="#Rat">Rat</a></pre>
    <p>将z设为x（生成一个拷贝）并返回z。</p>
    <h3 id="Rat.Add">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#364" title="View Source">Add</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) Add(x, y *<a href="#Rat">Rat</a>) *<a href="#Rat">Rat</a></pre>
    <p>将z设为x + y并返回z。</p>
    <h3 id="Rat.Sub">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#373" title="View Source">Sub</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) Sub(x, y *<a href="#Rat">Rat</a>) *<a href="#Rat">Rat</a></pre>
    <p>将z设为x - y并返回z。</p>
    <h3 id="Rat.Mul">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#382" title="View Source">Mul</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) Mul(x, y *<a href="#Rat">Rat</a>) *<a href="#Rat">Rat</a></pre>
    <p>将z设为x * y并返回z。</p>
    <h3 id="Rat.Quo">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#390" title="View Source">Quo</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) Quo(x, y *<a href="#Rat">Rat</a>) *<a href="#Rat">Rat</a></pre>
    <p>如果y != 0会将z设为x/y并返回z；如果y==0会panic。</p>
    <h3 id="Rat.Scan">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#408" title="View Source">Scan</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) Scan(s <a href="fmt.htm">fmt</a>.<a href="fmt.htm#ScanState">ScanState</a>, ch <a href="builtin.htm#rune">rune</a>) <a href="builtin.htm#error">error</a></pre>
    <p>本方法实现了fmt.Scanner接口，将z设为读取到的数字。接受格式'e'、'E'、'f'、'F'、'g'、'G'、'v'；它们都是等价的。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-Rat-Scan">
            <div class="panel-heading" onclick="document.getElementById('ex-Rat-Scan').style.display = document.getElementById('ex-Rat-Scan').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-Rat-Scan">
                <div class="panel-body">
                    <pre><span class="com">// The Scan function is rarely used directly;</span>
<span class="com">// the fmt package recognizes it as an implementation of fmt.Scanner.</span>
r := new(big.Rat)
_, err := fmt.Sscan("1.5000", r)
if err != nil {
    log.Println("error scanning value:", err)
} else {
    fmt.Println(r)
}</pre>
                    <p>Output:
                    </p><pre>3/2
</pre>
                </div>
            </div>
        </div>
    </div>
    <h3 id="Rat.GobEncode">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#548" title="View Source">GobEncode</a> </h3>
    <pre class="funcdecl">func (x *<a href="#Rat">Rat</a>) GobEncode() ([]<a href="builtin.htm#byte">byte</a>, <a href="builtin.htm#error">error</a>)</pre>
    <p>本方法实现了gob.GobEncoder接口。</p>
    <h3 id="Rat.GobDecode">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#571" title="View Source">GobDecode</a> </h3>
    <pre class="funcdecl">func (z *<a href="#Rat">Rat</a>) GobDecode(buf []<a href="builtin.htm#byte">byte</a>) <a href="builtin.htm#error">error</a></pre>
    <p>本方法实现了gob.GobDecoder接口。</p>
    <h3 id="Rat.MarshalText">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#590" title="View Source">MarshalText</a> </h3>
    <pre class="funcdecl">func (r *<a href="#Rat">Rat</a>) MarshalText() (text []<a href="builtin.htm#byte">byte</a>, err <a href="builtin.htm#error">error</a>)</pre>
    <p>本方法实现了encoding.TextMarshaler接口。</p>
    <h3 id="Rat.UnmarshalText">func (*Rat) <a href="https://github.com/golang/go/blob/master/src/math/big/rat.go?name=release#595" title="View Source">UnmarshalText</a> </h3>
    <pre class="funcdecl">func (r *<a href="#Rat">Rat</a>) UnmarshalText(text []<a href="builtin.htm#byte">byte</a>) <a href="builtin.htm#error">error</a></pre>
    <p>本方法实现了encoding.TextUnmarshaler接口。</p>
</div>